# Makefile of NCNY
# Copyright (C) 2006  Maxym V. Dilay
#  
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

AS	=nasm
CFLAGS=-Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -I./include -pipe 
CPP     =gcc32 -E -nostdinc -I./include
CC      =gcc32
#CC	=tcc
#CFLAGS=-Wall -O  -I../include

source_dirs := kernel init

search_wildcards := $(addsuffix /*.c ,$(source_dirs)) 

kernel.bin:$(notdir $(patsubst %.c,%.o,$(wildcard $(search_wildcards))))
	$(AS) -felf boot/start.asm -o start.o
#	$(CC) $(CFLAGS) -Wl,-O1 -Wl,-s -Wl,-x start.o $^ -o $@ -Wl,-T boot/link.ld
	ld -s -x -T boot/link.ld -o $@ start.o $^ -melf_i386 -Map linkmap.txt

VPATH := $(source_dirs)
     
%.o: %.c
	$(CC) -c $(addprefix -I,$(source_dirs)) $(CFLAGS) -o $*.o $<

.PHONY: clean

clean:
	rm -rf *.o *.d

include $(wildcard *.d) 
